package com.huajin.codetest.algorithm;

/**
 * https://leetcode.cn/problems/happy-number/description/
 *https://leetcode.cn/problems/add-digits/description/?envType=study-plan-v2&envId=primers-list
 * https://leetcode.cn/problems/subtract-the-product-and-sum-of-digits-of-an-integer/description/?envType=study-plan-v2&envId=primers-list
 *
 * 取模(%)：获取
 * 整除(/)：去除
 */
public class MathTest {

    public static void main(String[] args) {
        System.out.println(sum(10));
        System.out.println(sum(38));
    }

    /**
     * 数字之和
     * 7651
     */
    public static int sum(int num) {
        while (num >= 10) {
            int sum = 0;
            while (num > 0) {
                sum += num % 10;
                num /= 10;
            }
            num = sum;
        }
        return num;
    }

}
